<script lang="ts" setup>
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStoreHook } from '@store/user'
const userStore = useUserStoreHook()
const router = useRouter()
const handleUserInfo = () => {
  userStore
    .getInfo()
    .then(() => {})
    .catch(() => {})
    .finally(() => {})
}

onMounted(async () => {
  handleUserInfo()
})
/** 登出 */
const logout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<template>
  <div class="heads">
    <div>
      <!-- <h1>网京</h1> -->
    </div>
    <div>
      <el-dropdown>
        <span class="el-dropdown-link">
          <h2>{{ userStore.nickname }}</h2>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item divided @click="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.heads {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
  width: 100%;
  padding: 10px 0;
}
.el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
</style>
